package com.leo.filter;

import com.leo.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName: MyFilter
 * @Description: ${description}
 * @Author: leo825
 * @Date: 2020-02-03 17:21
 * @Version: 1.0
 */

@Component
public class MyFilter implements Filter {

    @Autowired
    UserInfoService userInfoService;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("MyFilter1 执行过滤");
        //访问数据库
        List userInfoList = userInfoService.getUserInfoList();
        System.out.print("MyFilter1 信息: ");
        System.out.println(userInfoList);
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
    }
}
